<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/2/1
 * Time: 18:24
 */

namespace App\Http\Logics\MiniProgram;


use App\District;
use App\Http\Logics\BaseLogic;
class DistrictLogic extends BaseLogic
{
    public static function getDistrictList($data)
    {
        $district = District::where(function ($query) use ($data){
            if (isset($data['citycode']) && $data['citycode']){
                $query->where('citycode', $data['citycode']);
            }
        })->get();

        if (empty($district)){
            return self::response(self::CONTENT_IS_EMPTY);
        }

        return self::response(self::SUCCESS, $district);
    }

    public static function setDistrictIsShow($data)
    {
        $district = District::where('adcode', $data['adcode'])->first();
        if (empty($district)){
            return self::response(self::CONTENT_IS_EMPTY);
        }
        $district->is_show = !$district->is_show;
        if (!$district->save()){
            return self::response(self::OBJECT_SAVE_FAIL);
        }
        return self::response(self::SUCCESS, $district);
    }
}